import java.sql.*;


public class test1022 {
    public static void main(String[] args) {
        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;

        try{
            //加载数据库厂商驱动
        Class.forName("com.mysql.cj.jdbc.Driver");

           connection = DriverManager.getConnection(
                    "jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&allowPublicKeyRetrieval" + "=true&useSSL=false","root","Rsa181210");

            statement=connection.createStatement();

            resultSet=statement.executeQuery("select * from exam_result limit 3");

            while(resultSet.next()){
                long id=resultSet.getLong(1);
                String name=resultSet.getString(2);
                long chinese=resultSet.getLong(3);
                long math=resultSet.getLong(4);
                long english=resultSet.getLong(5);


                System.out.println("id="+id+"  name: "+name+"  chinese="+chinese+"  math="+math+"  english="+english);

            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            if(resultSet!=null){
                try {
                    resultSet.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
